<template>
  <div>
    <BasicTable @register="registerTable">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="[
            {
              tooltip: '查看',
              icon: 'clarity:note-edit-line',
              onClick: handleView.bind(null, record.id),
            },
          ]" />
        </template>
      </template>
    </BasicTable>

  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { list, view, getChildren } from '/@/api/base/area';
import { columns, searchFormSchema } from './area.data';
import { useMessage } from '/@/hooks/web/useMessage';
import { useModal } from '/@/components/Modal';
const { createMessage } = useMessage();

export default defineComponent({
  name: 'Area',
  components: { BasicTable, TableAction, },
  setup() {
    const [registerModal, { openModal, setModalProps }] = useModal();
    const [registerTable, { reload, }] = useTable({
      title: '列表',
      api: list,
      columns,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        showAdvancedButton: false,
        showResetButton: false,
        autoSubmitOnEnter: true,
      },
      canColDrag: true,
      useSearchForm: true,
      showTableSetting: false,
      bordered: true,
      showIndexColumn: false,
      actionColumn: {
        width: 120,
        title: '操作',
        dataIndex: 'action',
        fixed: false,
      },
    });


    function doSearch() {
      reload();
    }

    function handleView(id) {
      createMessage.success({
        content: '查看行政区域，id=' + id,
        duration: 1,
      });
    }

    function handleSuccess() {
      setTimeout(() => {
        reload();
      }, 200);
    }

    return {
      registerTable, registerModal, handleSuccess, doSearch, handleView,
    };
  },
});
</script>
